package com.mhs.dataclassification.processSize;

//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.io.ObjectOutputStream;

import android.database.sqlite.SQLiteDatabase;

import com.mhs.DTO.MySQLiteHelper;
import com.mhs.DTO.ThuocDTO;

public class ProcessSize_ThuocDTO {

	public static int calculateSize_ThuocDTO_Insert(ThuocDTO t) {
		int sizeRecord;
//		size int = 4 bytes
//		mathuocclient, mathuoc, maloaithuoc, hinhanh, tenthuoc, sodangky, thanhphan, dangbaoche, donggoi, congtysanxuat,
//		chidinh, chongchidinh, tuongtacthuoc, chuydephong,
//		tacdungphu, lieuluong, nhanbiet, baoquan, K, size, TS, TTL
		sizeRecord = 4 + 4 + 4 + sizeOfString(t.getHINHANH()) + sizeOfString(t.getTENTHUOC()) + sizeOfString(t.getSODANGKY())
				 + sizeOfString(t.getTHANHPHAN()) + sizeOfString(t.getDANGBAOCHE()) + sizeOfString(t.getDONGGOI())
				 + sizeOfString(t.getCONGTYSANXUAT()) + sizeOfString(t.getCHIDINH()) + sizeOfString(t.getCHONGCHIDINH())
				 + sizeOfString(t.getTUONGTACTHUOC()) + sizeOfString(t.getCHUYDEPHONG()) + sizeOfString(t.getTACDUNGPHU())
				 + sizeOfString(t.getLIEULUONG()) + sizeOfString(t.getNHANBIET()) + sizeOfString(t.getBAOQUAN())
				 + 4 + 4 + 8 + 4;
		return sizeRecord;	
	}
	
	private static int sizeOfString(String sValue){
		return sValue.getBytes().length;
	}
	
	@SuppressWarnings("unused")
	private void updateSize_ThuocDTO(ThuocDTO thuocNew, SQLiteDatabase database, MySQLiteHelper dbHelper){
		database = dbHelper.getWritableDatabase();
		int sizeNew = calculateSize_ThuocDTO_Insert(thuocNew);
		String sQuery = "update thuoc set size = " + sizeNew + " where mathuoc = " + thuocNew.getMATHUOC() + ";";		
		database.execSQL(sQuery);
	}
}
